<template>
    <div id="system" class="warp system">
        <postHead active="home" :showAction="true"></postHead>

        <div class="container">
            <div class="main-left">

                <div class="system-lt">
                    <ul class="sidemenu">
                        <li @click="toBaseInfo"><a ><span class="iconmd iconmd-files"></span>基本信息</a></li>
                        <li  class="active"><a><span class="iconmd iconmd-user"></span>账号管理</a></li>
                        <li @click="toChildManage"><a><span class="iconmd iconmd-adduser"></span>子账号管理</a></li>
                    </ul>
                </div>
            </div>
            <!-- /.main-left -->
            <!-- left /end -->
            <div class="main-right">

                <div class="system-rt">

                    <div class="account">
                        <div class="account-info1">
                            <div class="tofu-title systitle">基本信息</div>
                            <div class="account-info1-content">
                                <ul class="accountlist">
                                    <li><span class="accw1">账户类型：</span> <span>企业主账号</span></li>
                                    <li><span class="accw1">登录账户：</span> <span>landleap@163.com</span></li>
                                
                                    <li class="jaycontactmen">
                                        <div class="acclistcon">
                                            <div class="acclistcon-lt">
                                                <span class="accw1">联系人：</span> <span>王凯</span>
                                            </div>
                                            <div class="acclistcon-rt">
                                                <a>修改</a>
                                            </div>
                                        </div> <!-- /.acclistcon -->

                                        <div class="acclistcon hidden">
                                            <div class="acclistcon-lt">
                                                <div class="acclistcon-lt-con">
                                                    <span class="accw1">联系人：</span> <input type="text" value="刘建平"
                                                        id="contactmen" class="form-control">
                                                </div>
                                            </div>
                                            <div class="acclistcon-rt">
                                                <a class="btn btn-default btn-sm">取消</a> <a
                                                    class="btn btn-primary btn-sm">保存</a>
                                            </div>
                                        </div> <!-- /.acclistcon -->
                                    </li>
                                    <li class="jaycontacttelphone">
                                        <div class="acclistcon">
                                            <div class="acclistcon-lt">
                                                <span class="accw1">联系电话：</span> <span>13327970962</span>
                                            </div>
                                            <div class="acclistcon-rt">
                                                <a>修改</a>
                                            </div>
                                        </div> <!-- /.acclistcon -->

                                        <div class="acclistcon hidden">
                                            <div class="acclistcon-lt">
                                                <div class="acclistcon-lt-con">
                                                    <span class="accw1">联系电话：</span> <input type="text"
                                                        value="13527900935" id="contacttelphone" class="form-control">
                                                </div>
                                            </div>
                                            <div class="acclistcon-rt">
                                                <a class="btn btn-default btn-sm">取消</a> <a
                                                    class="btn btn-primary btn-sm">保存</a>
                                            </div>
                                        </div> <!-- /.acclistcon -->
                                    </li>
                                    <li class="jaycontactemail">
                                        <div class="acclistcon">
                                            <div class="acclistcon-lt">
                                                <span class="accw1">联系邮箱：</span> <span>570848924@qq.com</span>
                                            </div>
                                            <div class="acclistcon-rt">
                                                <a>修改</a>
                                            </div>
                                        </div> <!-- /.acclistcon -->

                                        <div class="acclistcon hidden">
                                            <div class="acclistcon-lt">
                                                <div class="acclistcon-lt-con">
                                                    <span class="accw1">联系邮箱：</span> <input type="text"
                                                        value="landleap@163.com" id="contactemail" class="form-control">
                                                </div>
                                            </div>
                                            <div class="acclistcon-rt">
                                                <a class="btn btn-default btn-sm">取消</a> <a
                                                    class="btn btn-primary btn-sm">保存</a>
                                            </div>
                                        </div> <!-- /.acclistcon -->
                                    </li>

                                    <li class="jaysendemail">
                                        <div class="acclistcon">
                                            <div class="acclistcon-lt">
                                                <span class="accw1">发送邮箱：</span> <span></span>
                                            </div>
                                            <div class="acclistcon-rt">
                                                <a>修改</a>
                                            </div>
                                        </div> <!-- /.acclistcon -->

                                        <div class="acclistcon hidden">
                                            <div class="acclistcon-lt">
                                                <div class="acclistcon-lt-con">
                                                    <span class="accw1">发送邮箱：</span> <input type="text" value=""
                                                        id="SendEmail" class="form-control">
                                                    <span class="accw1" style="width:80px">授权密钥：</span>
                                                    <input type="text" value="" id="SendEmailPWD" class="form-control">
                                                </div>
                                            </div>
                                            <div class="acclistcon-rt">
                                                <a class="btn btn-default btn-sm">取消</a> <a
                                                    class="btn btn-primary btn-sm">保存</a>
                                            </div>
                                        </div> <!-- /.acclistcon -->
                                    </li>
                                </ul>
                            </div>
                        </div>
                        <!-- /.account-info1 -->

                        <div class="account-info1">
                            <div class="tofu-title systitle">套餐情况</div>
                            <table class="table table-border" style="text-align: center;">
                                <tbody>
                                    <tr>
                                        <th style="text-align: center;">可设子账号数</th>
                                        <th style="text-align: center;">可发布岗位数</th>
                                        <th style="text-align: center;">可下载简历数</th>
                                        <th style="text-align: center;">简历库空间（份）</th>
                                        <th style="text-align: center;">生效日期</th>
                                        <th style="text-align: center;">停止日期</th>
                                    </tr>
                                    <tr>
                                        <td>10</td>
                                        <td>50</td>
                                        <td>500</td>
                                        <td>5000</td>
                                        <td>2016-05-29</td>
                                        <td>永久免费</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import {
    regionData,
    codeToText
} from "element-china-area-data";
import postHead from '@/components/postHead.vue';
import homeapi from '@/api/api.js'
import until from '@/api/until'
export default {
    name: 'login',
    data() {
        return {
            phone: "",
            haveCheck: false,
            code: "",
            title: "",
            loginType: 1,
            loginCode: 1,
            active: 2,
            form: {
                annualRevenue: "",
                annualRevenueName: '',
                contactName: "",
                creditCode: "",
                email: "",
                enterpriseIndustry: "",

                enterpriseNature: "",

                enterpriseScale: "",

                landlineNumber: "",
                licenceImg: "",
                licenceImgUrl: "",
                listingType: "",
                listingTypeName: "",
                name: "",
                officialWebsite: "",
                phone: "",
                staffsNum: "",
                staffsNumName: '',
                wechatOfficialAccount: "",
                inviteCode: "",
                inviter: "",

                inviterPhone: "",

            },

            userForm: {
                inviteCode: "",
                inviter: "",
                inviterPhone: "",
                name: "",
                nickName: "",
                workplace: "",
                idCard: "",
                personHighestDegree: {

                },
                personImportantUnits: {

                }
            },
            enterpriseScaleList: [],
            enterpriseIndustry: [],
            enterpriseNatureList: [],
            staffsNumList: [],

            regionDatas: regionData,
            cateProps: {
                value: "value",
                label: "label",
                children: "children",
            },
            props: {
                value: "id",
                label: "text",
                children: "children",

            },
            showCode: true,
            time: 60,
        }
    },
    components: {
        postHead
    },
    mounted() {
        let title = this.$route.query.title
        if (title) {
            this.title = title
        }
        else {
            this.title = "AI爱招聘-注册"
        }
        this.getDictList();
        this.getIndustryList();
    },
    methods: {
        toChildManage(){
            this.$router.push("/company/childAccount")
        },
        toBaseInfo(){
            this.$router.push("/company/systeminfo")
        },
        toLogin() {
            this.$router.push("/login/loginnew")
        },
        setActive(type) {
            this.active = type;
        },
        //获取数据字典
        async getDictList() {
            let data = await homeapi.getDictList();
            if (data.code == 200) {
                this.enterpriseScaleList = data.result.enterpriseScale
                this.enterpriseNatureList = data.result.enterpriseNature
                this.staffsNumList = data.result.staffsNum
            }
        },
        deleteImg() {
            this.form.licenceImg = ""
            this.form.licenceImgUrl = ""
        },

        //获取行业列表
        async getIndustryList() {
            let data = await homeapi.getIndustryList();
            if (data.code == 200) {
                data.result.map(res => {
                    res.text = res.name;
                    if (res.child.length > 0) {
                        res.child.map(json => {
                            json.text = json.name
                        })
                        res.children = res.child;
                        res.children.map(json => {
                            if (json.child.length > 0) {
                                json.child.map(item => {
                                    item.text = item.name
                                })
                                json.children = json.child

                            }
                            else {
                                json.children = [
                                    {
                                        text: json.text,
                                        id: json.id
                                    }
                                ]
                            }
                        })
                    }
                    else {
                        res.children = [
                            {
                                text: res.text,
                                children: [{
                                    text: res.text,
                                    id: res.id
                                }]
                            }
                        ]
                    }
                })

                this.enterpriseIndustry = data.result

            }
        },




        async sendCode() {
            let phone = this.phone
            if (phone.length != 11) {
                this.$message.error("请传入正确的手机号")
                return false;
            }

            let data = await homeapi.sendCode({ phone });

            if (data.code == 200) {
                this.showCode = false
                this.getTimeNext();
            }
            else {
                this.$message.error(data.message)

            }
        },

        getTimeNext() {
            if (this.time > 0) {
                this.time = this.time - 1;
                setTimeout(() => {
                    this.getTimeNext();
                }, 1000)
            }
            else {
                this.showCode = true;
                this.time = 60
            }
        },
        setCheck() {
            this.haveCheck = true;
        },
        async toRegister() {
            if (this.active == 2) {
                let code = this.code
                let phone = this.phone

                let type = this.active
                let form = this.userForm;
                form.code = code;
                form.phone = phone
                this.loading = true;
                let data = await homeapi.registerUser(form);
                if (data.code == 200) {
                    this.$message.success("注册成功")
                    until.setCookie("token", data.result);
                    this.$router.push("/user")


                }
                else {
                    this.loading = false
                    this.$message.error(data.message)
                }
            }
            else {
                let code = this.code
                let phone = this.phone
                let type = this.active
                let form = this.form;
                form.code = code;
                form.phone = phone
                this.loading = true;
                let data = await homeapi.registerCompany(form);
                if (data.code == 200) {
                    this.$message.success("注册成功")
                    until.setCookie("token", data.result);
                    this.$router.push("/")



                }
                else {
                    this.loading = false
                    this.$message.error(data.message)
                }
            }

        },
        async getUserInfo() {
            let data = await homeapi.getUserinfo();
            if (data.code == 402) {

            }
            if (data.code == 403) {
                this.$router.push("/company")

            }
            if (data.code == 200) {

            }

        },

        async sureEdit() {
            if (this.active == 1) {
                let form = this.form;

                let data = await homeapi.editCompany(form);
                if (data.code == 200) {
                    this.loading = false
                    this.$message.success("注册成功")
                    this.$router.push("/")
                }
            }
            else {
                let form = this.form;

                let data = await homeapi.editUser(form);
                if (data.code == 200) {
                    this.loading = false
                    this.$message.success("注册成功")
                    this.$router.push("/")
                }
            }

        },
        async changeFile(e) {
            if (e.target.files.length > 0) {
                let file = e.target.files[0]
                var formData = new FormData();
                // 服务端要求参数是 pic1 
                formData.append('file', file);
                let data = await homeapi.uploadFile(formData);
                if (data.code == 200) {

                    this.form.licenceImgUrl = data.result.url
                    this.form.licenceImg = data.result.path
                }
            }

        }


    }
}

</script>

<style scoped lang="less">
.footer {
    position: fixed;
}
.sidemenu li{
    font-size: 16px;
}

.container {
    width: 100%;
    height: calc(100vh - 125px);
    overflow: auto;
    margin-top: 15px;
}

.main-left {
    position: fixed;
    top: 95px;
    bottom: 30px;
    background: #fff;
}

.system-lt {
    border: 0px;
}

.system-rt {
    border: 0px;
}

.main-right {
    margin-left: 0px;
}

.navbar-header {
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

.navbar-header span {
    font-size: 24px;
    color: #FC7B24;
    font-weight: bold;
}

.upload_div {
    width: 80px;
    height: 80px;
    border: 1px solid #e6e6e6;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
}

.upload_div input {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0;
    cursor: pointer;
}

.upload_div i {
    font-size: 18px;
}

.register-form-control {
    display: flex;
    align-items: center;
    justify-content: flex-start;
}
</style>
